'''
timeout: 设置超时
1、接口响应时间比较久，默认时间返回不了，通过timeout设置大一点的超时时间
比如上传大文件
2、测试接口的性能，看是否能在规定的时间内返回

'''

import requests
# 淘宝查询手机号码归属地的接口
#url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=18729460301"
'''
for i in range(10):
    # Connection to tcc.taobao.com timed out 超时了显示
    r = requests.get(url,timeout = 0.5)  # 时间内是否能返回
    print(r.text)

'''
'''
设置代理
1、通过界面操作某个功能正常，但是通过对某个接口功能不正常
   分别抓取界面、自动化的包，对比差异
2、通过同一个IP频繁访问某个地址，可能会被服务器屏蔽，设置代理
发出去的是请求，显示的是代理地址   
'''
'''
proxy={
    #协议：代理地址
    "http":"http://127.0.0.1:8888",
    "https":"http://127.0.0.1:8888"
}

r = requests.get("http://www.baidu.com",proxies=proxy) # 需打开fiddler
print(r.text)

r = requests.get("http://www.qq.com",proxies=proxy,verify = False)  #设置不校验证书
print(r.text)

'''
# 注册接口实现自动化
s  = requests.Session()
url = "http://192.168.150.84:8088/futureloan/mvc/api/member/register"

cs = {
"mobilephone":	"1234567890",
"pwd":"1234566",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("手机号长度短：",r.text)

print("=====================================================================================")
cs = {
"mobilephone":	"123456789012",
"pwd":"1234566",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("手机号长度过长:",r.text)



print("=====================================================================================")
cs = {
"mobilephone":	"%#@",
"pwd":"1234566",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("手机号为特殊字符：",r.text)

print("=====================================================================================")
cs = {
"mobilephone":	" ",
"pwd":"1234566",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("手机号码为空：",r.text)

print("=====================================================================================")
cs = {
"mobilephone":	"",
"pwd":"12345678",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("手机号什么都不填，不加空格：",r.text)


print("========================================密码=============================================")
cs = {
"mobilephone":	"15191629439",
"pwd":"12345",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("密码长度过短：",r.text)


print("=====================================================================================")
cs = {
"mobilephone":	"15191629439",
"pwd":"1234567891234567890",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("密码长度过长：",r.text)

print("=====================================================================================")
cs = {
"mobilephone":	"15191629439",
"pwd":" ",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("密码为空：",r.text)

print("=====================================================================================")
cs = {
"mobilephone":	"15191629439",
"pwd":"",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("密码错误，不加空格：",r.text)


print("=====================================================================================")
cs = {
"mobilephone":	"15192629489",
"pwd":"桃李春风一杯酒",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("密码为中文：",r.text)

print("=====================================================================================")
cs = {
"mobilephone":	"151926299",
"pwd":"1234",
"regname"	:"hello "

}
r= s.post(url,data=cs)
print("手机号密码同时错误，预期应是手机号错误：",r.text)


print("=======================================注册名==============================================")
cs = {
"mobilephone":	"15191629436",
"pwd":"1234567",
"regname"	:" "

}
r= s.post(url,data=cs)
print("注册名为空：",r.text)

print("=====================================================================================")
cs = {
"mobilephone":	"15192629989",
"pwd":"桃李春风一杯酒",
"regname"	:"hello7uijruwe98ey hc;jvclkjvckg;reig67t89yu0i-t4hcilehwcfiwufw498tiw8p9u4jifjigowjepog9wgiilsejgoijge;rjljgnjwo;e "

}
r= s.post(url,data=cs)
print("注册名超长：",r.text)



print("=====================================================================================")
cs = {
"mobilephone":	"15191629436",
"pwd":"1234567",
"regname"	:""

}
r= s.post(url,data=cs)
print("注册名为空，不加空格，什么都不填：",r.text)


print("==========================================手机号已被注册================================================")
cs = {
"mobilephone":	"15191629439",
"pwd":"1234567",
"regname"	:" "

}
r= s.post(url,data=cs)
print("手机号已注册：",r.text)


'''
1. 手机号正确（实际没有注册过），密码正确，注册名超长，
   预期注册成功或提示注册名长度不正确，实际返回服务器异常
2. 手机号正确，密码错误，提示密码错误
   手机号错误，密码正确时，提示手机号错误
   手机号、密码同时错误时，预期提示手机号错误，实际提示的是密码错误
3. 密码输入包含空格、中文字符，预期报错密码格式不正确，实际注册成功了
'''